﻿//
// <author>David Nohejl</author>
//

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;

namespace WPFTrees.Parser
{
    /// <summary>
    /// Reprezentuje data uzlu.
    /// </summary>
    public class NewickNode : IComparable<NewickNode>
    {
        string label;
        
        /// <summary>
        /// Gets or sets label of the node.
        /// </summary>
        public string Label { get { return label; } set { label = value; } }

        /// <summary>
        /// Initializaes new instance of NewickNode.
        /// </summary>
        /// <param name="label">Textual label of node.</param>
        /// <param name="isLeaf">True if node is leaf.</param>
        public NewickNode(string label, bool isLeaf)
        {
            this.label = label;
            this.isLeaf = isLeaf;
        }

        /// <summary>
        /// Compares this instance to another.
        /// </summary>
        /// <param name="other">Another instance of NewickNode</param>
        /// <returns></returns>
        public int CompareTo(NewickNode other)
        {
            return label.CompareTo(other.label);
        }

        bool bCollapsed = false;
        /// <summary>
        /// True pokud je tento uzel sbaleny.
        /// </summary>
        public bool IsCollapsed
        {
            get { return bCollapsed; }
            set { 
                bCollapsed = value;
                uiElement.Visibility = value 
                    ? Visibility.Collapsed 
                    : Visibility.Visible;
                
                if (uiBranchElement != null)
                    uiBranchElement.Visibility = uiElement.Visibility;

                if (groupInfo != null)
                    groupInfo.Shape.Visibility = uiElement.Visibility;
            }
        }

        FrameworkElement uiElement;
        /// <summary>
        /// Object representing visual rendering of node.
        /// </summary>
        public FrameworkElement VisualElement { 
            get { return uiElement; } 
            set { uiElement = value; } 
        }


        FrameworkElement uiBranchElement;
        /// <summary>
        /// Object representing visual edge between node and its parent.
        /// </summary>
        public FrameworkElement BranchToParentElement { 
            get { return uiBranchElement; } 
            set { uiBranchElement = value; }
        }

        bool isLeaf;

        /// <summary>
        /// True pokud je to list, false pokud jde o vnitrni uzel nebo koren.
        /// </summary>
        public bool IsLeaf
        {
            get
            {
                return isLeaf;
            }
        }

        GroupInfo groupInfo;

        /// <summary>
        /// Informace o skupine kterou tento uzel reprezentuje.
        /// </summary>
        public GroupInfo GroupInfo { 
            get { return groupInfo; } 
            set { groupInfo = value; } 
        }

        double? branchLenght = null;

        /// <summary>
        /// Delka hrany mezi rodicem a timto uzlem. Reprezentuje evolucni 
        /// vzdalenost. Null pokud neni znama.
        /// </summary>
        public double? BranchLenght {
            get {return branchLenght; } 
            set { branchLenght = value; } 
        }
    }
}
